#include<stack>
using namespace std;

static 	stack<int> pids;;
class Hidden {
	private :
	public :
	static void add(int pid) {
		pids.push(pid);
	}
	static int getLatestRunning() {
		while(!pids.empty()) {
			int pid = pids.top();
			if(kill(pid, 0) == 0) {
				pids.pop();
				return pid;
			}
			if (errno == ESRCH) {
				pids.pop();
				Utility::out_start();
				cout<<endl<<"["<<pid<<"]"<<" Done"<<endl; 
				Utility::out_end();
				continue;
			}	
		}
		return -1;

	}	
	
	static void check() {
		int pid=-1;
		while(!pids.empty()) {
			pid = pids.top();
			if(kill(pid, 0) == 0) {
				break;
			}	
			if (errno == ESRCH) {
				pids.pop();
				Utility::out_start();
				cout<<endl<<"["<<pid<<"]"<<" Done"<<endl; 
				Utility::out_end();
				continue;
			}	
		}
	}

	static void stop() {
		int pid=-1;
		pid = getLatestRunning();	
		while(pid!=-1) {
			kill(pid,9);
			Utility::out_start();
			cout<<endl<<"["<<pid<<"]"<<" Stopped"<<endl; 
			Utility::out_end();
			pid = getLatestRunning();	
		}
	}
};
